import com.intellij.facet.FacetManager;
import com.intellij.facet.FacetTypeId;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.fileEditor.impl.EditorTabbedContainer;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiPlainText;
import com.yijiupi.plugin.test.TestToolWindow;
import com.yijiupi.plugin.test.facet.DemoFacet;
import com.yijiupi.plugin.test.facet.DemoFacetType;
import com.yijiupi.plugin.test.header.MyEditorHeader;
import com.yijiupi.plugin.test.service.TestMoudle;
import com.yijiupi.plugin.test.service.impl.TestMoudleImpl;

public class ActionTest extends AnAction {

	@Override
	public void actionPerformed(AnActionEvent e) {
		// TODO: insert action logic here
		PsiManager.getInstance(e.getProject()).findFile(e.getProject().getProjectFile());
		//获取编辑框
		Editor editor=e.getRequiredData(CommonDataKeys.EDITOR);

		MyEditorHeader myEditorHeader=new MyEditorHeader();
		editor.setHeaderComponent(myEditorHeader.getPanel1());
		//获取工具窗口
		ToolWindowManager toolWindowManager=ToolWindowManager.getInstance(e.getProject());
		ToolWindow testToolWindow=toolWindowManager.getToolWindow("狗屎");
		System.out.println("编辑器种类:"+editor.getEditorKind().name());
		String text=editor.getDocument().getText();
		System.out.println(text);

		VirtualFile virtualFile= VirtualFileManager.getInstance().findFileByUrl("http://www.baidu.com");

		//项目级别的服务要通过项目拿到服务
		TestMoudle testMoudle=ServiceManager.getService(TestMoudle.class);
		TestMoudle testMoudle2=ServiceManager.getService(TestMoudle.class);
		testMoudle.testGetData();
		//通过模块拿facet
		Module[] modules= ModuleManager.getInstance(e.getProject()).getModules();
		for(Module module:modules){
			DemoFacet acet=FacetManager.getInstance(module).getFacetByType(new FacetTypeId<>(DemoFacetType.FACET_ID));
		}
	}
}
